#ifndef MAINIMAGESCENE_H
#define MAINIMAGESCENE_H

#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsView>

class Pixmap : public QObject, public QGraphicsPixmapItem
{
    Q_OBJECT
    Q_PROPERTY(QPointF pos READ pos WRITE setPos)
public:
    Pixmap(const QPixmap &pix)
        : QObject(), QGraphicsPixmapItem(pix)
    {
        setCacheMode(DeviceCoordinateCache);
    }
};

class MainImageScene : public QGraphicsScene
{
    Q_OBJECT
public:
    explicit MainImageScene(QObject *parent = 0);
    void setView(QGraphicsView *viewPtr_t);
    QRectF getROI();
    bool isSetROI();
    bool resetROI();


signals:
    void sendImage(QImage image);

public slots:

protected slots:
    void updateImage(QImage image);
    void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);

private:
    bool drawImage();
    bool drawROIRect();
    bool clearImage();
    bool clearROIRect();

private:
    QGraphicsView *viewPtr;
    QGraphicsPixmapItem* pixmapPtr;
    QGraphicsRectItem *ROIRectPtr;
    QRectF ROIRect;
    bool mousePressedFlag;
    QPointF pressPoint;
    bool startDrawROIFlag;
    bool labeledFlag;
    QPixmap originalImage;
    int imageWidth;
    int imageHeight;
    
};

#endif // MAINIMAGESCENE_H
